﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data;
using DTO;
using UTIL;

namespace DAO
{
    public class GiamGiaDao
    {
        public static List<DTO.GiamGiaDto> LayDanhSachGiamGia()
        {
            SqlConnection cnn = DataConnector.MakeConnection();
            string sql = "Select * From GiamGia";
            SqlCommand cmd = new SqlCommand(sql, cnn);
            SqlDataReader dr = cmd.ExecuteReader();
            List<DTO.GiamGiaDto> list = new List<GiamGiaDto>();
            DTO.GiamGiaDto giam = null;
            while (dr.Read())
            {
                giam = new GiamGiaDto();
                giam.ID = (int)dr["ID"];
                giam.MucGiam = (int)dr["mucgiam"];
                giam.ThangDiem = (int)dr["thangdiem"];
                list.Add(giam);
            }
            cnn.Close();

            return list;
        }
        public static GiamGiaDto LayDanhGiamGiaTheoID(int id)
        {
            SqlConnection cnn = DataConnector.MakeConnection();
            string sql = "Select * From GiamGia Where ID="+id;
            SqlCommand cmd = new SqlCommand(sql, cnn);
            SqlDataReader dr = cmd.ExecuteReader();

            DTO.GiamGiaDto giam = null;
            if (dr.Read())
            {
                
                giam = new GiamGiaDto();
                giam.ID = (int)dr["ID"];
                giam.MucGiam = (int)dr["mucgiam"];
                giam.ThangDiem = (int)dr["thangdiem"];
                
            }
            cnn.Close();

            return giam;
        }
    }
}
